package office.action.sale;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import current.security.user.domain.User;

import office.action.sale.form.TrackingInfoForm;
import office.bo.sale.impl.TrackingInfo;
import office.service.sale.ITrackingService;
import platform.common.action.BaseAction;
import platform.util.DateUtil;

@Namespace("/trackingInfo")
@ParentPackage("struts-base")
@Controller("trackingInfoAction")
@Scope("prototype")
public class TrackingInfoAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	@Resource
	private ITrackingService trackingService;
	private List<TrackingInfo> tList;
	private TrackingInfoForm tif;
	
	@Action(value="gotoTrackingInfoMenu",results={@Result(location="/pages/sale/trackingInfoXml.jsp")})
	public String gotoTrackingInfoMenu(){
		return "success";
	}
	
	@Action(value="gotoDeleteTrackingInfo",results={@Result(location="/pages/sale/trackingInfoDel.jsp")})
	public String gotoDeleteTrackingInfo(){
		return "success";
	}
	
	@Action(value="delTrackingInfo")
	public String delTrackingInfo(){
		trackingService.deleteTrackingInfo(tif.getId());
		this.getAjaxMessagesJson().setMessage(true, "", "删除成功");
		return RESULT_AJAXJSON;
	}
	
	@Action(value="editTrackingInfo")
	public String editTrackingInfo(){
		TrackingInfo trackingInfo = new TrackingInfo();
		if(tif != null && tif.getId() != null && !tif.getId().equals("")){
			trackingInfo.setId(tif.getId());
		}else{
			trackingInfo.setId(null);
		}
		User user = new User();
		user.setId(getUserMap().get("userId").toString());
		trackingInfo.setName(tif.getName());
		trackingInfo.setCreateDate(tif.getCreateDate());
		trackingInfo.setType(tif.getType());
		trackingInfo.setCreateUser(getUserId());
		trackingInfo.setStatus(tif.getStatus());
		trackingInfo.setCreateDate(DateUtil.getDate());
		trackingService.saveTrackingInfo(trackingInfo);
		this.getAjaxMessagesJson().setMessage(true, "", "编辑成功");
		return RESULT_AJAXJSON;
	}
	 
	@Action(value="gotoEditTrackingInfo",results={@Result(location="/pages/sale/trackingInfoEdit.jsp")})
	public String gotoEditTrackingInfo()throws Exception{
		if(tif !=null && tif.getId() != null){
			TrackingInfo trackingInfo = trackingService.getTrackingInfoById(tif.getId());
			tif.setId(trackingInfo.getId().toString());
			tif.setCreateDate(trackingInfo.getCreateDate());
			tif.setCreateUser(trackingInfo.getCreateUser());
			tif.setName(trackingInfo.getName());
			tif.setStatus(trackingInfo.getStatus());
			tif.setType(trackingInfo.getType());
		}
		return "success";
	}
	
	@Action(value="getAllTrackingInfo",results={@Result(location="/pages/sale/trackingInfo.jsp")})
	public String getAllTrackingInfo(){
		tList = trackingService.getAllTrackingInfo();
		return "success";
	}

	public ITrackingService getTrackingService() {
		return trackingService;
	}

	public void setTrackingService(ITrackingService trackingService) {
		this.trackingService = trackingService;
	}

	public List<TrackingInfo> gettList() {
		return tList;
	}

	public void settList(List<TrackingInfo> tList) {
		this.tList = tList;
	}

	public TrackingInfoForm getTif() {
		return tif;
	}

	public void setTif(TrackingInfoForm tif) {
		this.tif = tif;
	}
}
